<?php
namespace App\Models\Admin;

use Illuminate\Support\Facades\DB;

class CategoryModel extends BaseModel
{
    /**
     * 用户注册属性
     */

    protected $table = 'category';
    protected $fillable = [
        'id','name','pid','del','created_at','updated_at',
    ];

    public static function getSubsByCates($pids)
    {
        $models = CategoryModel::where('del',0)
            ->whereIn('pid',$pids)
            ->get();
        if (!count($models)) { return ''; }
        $dataArr = array();
        foreach ($models as $k=>$model) {
            $dataArr[$k]['id'] = $model->id;
            $dataArr[$k]['name'] = $model->name;
        }
        return $dataArr;
    }


    /**
     * 根据id数组,返回对应的名称数组
    */
    public static function getNames($id){
         return self::wherein('id',$id)->pluck('name')->toArray();
    }

    public static function getName($id){
         $one= self::where('id',$id)->select('name')->first()->toArray();
         if($one){
            return $one['name'];
         }else{
            return '未知';
         }
    }



}